package com.map;

import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import java.io.IOException;
import java.util.List;

import static com.map.Point.Wgs84ToMector;
import static com.map.TileIndex.GetTiles;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
//        test(new TileIndex(26434,11859,15));
        try {
            downImg(40.1072433277176,40.3880483043859,110.336275542382,110.715969196022,1,16,"E:\\test.db");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static  void downImg(double latMin,double latMax,double lonMin,double lonMax,
                        Integer levelMin,Integer levelMax,String path) throws IOException {
        SqliteHelper sqliteHelper=new SqliteHelper(path);
        CloseableHttpClient client =   HttpClients.createDefault();
        Point min=new Point(lonMin,latMin);
        Point max=new Point(lonMax,latMax);
        min=Wgs84ToMector(min);
        max=Wgs84ToMector(max);
        for (Integer z=levelMin;z<=levelMax;z++){
            System.out.println("下载瓦片等级"+z);
            List<TileIndex> list=GetTiles(min,max,z);
            for (TileIndex  tileIndex:list
                 ) {
                System.out.println("下载瓦片"+z+"-"+tileIndex.getX()+"-"+tileIndex.getY());
                sqliteHelper.httpGetImg(client,tileIndex);
            }
        }
        sqliteHelper.close();
        client.close();
        System.out.println("运行完成");


    }

}
